﻿<UserControl x:Class="WhiteFlow.DevTrackingTool.UI.Views.TasksListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:wfBehaviors="clr-namespace:WhiteFlow.Wpf.Common.Behaviors;assembly=WhiteFlow.Wpf.Common"
             xmlns:wfCtlCommon="clr-namespace:WhiteFlow.Wpf.Controls.Common;assembly=WhiteFlow.Wpf.Controls"
             xmlns:wfCtlText="clr-namespace:WhiteFlow.Wpf.Controls.Text;assembly=WhiteFlow.Wpf.Controls"
             xmlns:behaviors="clr-namespace:WhiteFlow.DevTrackingTool.UI.Behaviors"
             xmlns:controls="clr-namespace:WhiteFlow.DevTrackingTool.UI.Controls"
             xmlns:converters="clr-namespace:WhiteFlow.DevTrackingTool.UI.Converters"
             mc:Ignorable="d"
             d:DesignHeight="371" 
             d:DesignWidth="743">
    
    <UserControl.Resources>
        <converters:IsNullToBooleanConverter x:Key="IsNullToBooleanConverter" />
        <converters:TimeSpanConverter x:Key="TimeSpanConverter" />
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <TextBlock Text="Tasks List" 
                   Grid.Row="0"
                   Margin="20,0,0,0" 
                   FontSize="50" 
                   Foreground="{StaticResource ResourceKey=BlueFgBrush}" 
                   FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />
        
        <Grid Grid.Row="1">
            <DockPanel LastChildFill="True">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="5" />
                        <RowDefinition Height="auto" MinHeight="120" MaxHeight="250" />
                    </Grid.RowDefinitions>
                    
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="280" />
                        </Grid.ColumnDefinitions>

                        <DataGrid Name="TasksGrid"
                                  ItemsSource="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay.ExecutedTasks}" 
                                  CanUserAddRows="False"
                                  CanUserReorderColumns="False"
                                  CanUserResizeRows="False"
                                  CanUserSortColumns="False"
                                  SelectedItem="{Binding Path=SelectedTask, Mode=OneWayToSource}"
                                  SelectedIndex="{Binding Path=SelectedTaskIndex, Mode=OneWayToSource}"
                                  SelectionUnit="FullRow"
                                  AutoGenerateColumns="False"
                                  behaviors:DataGridBehavior.EditOnKeyDown="True">

                            <DataGrid.Columns>
                                <DataGridTemplateColumn Header="Location" Width="auto" MinWidth="55">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=Location}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <wfCtlText:AutoCompleteTextBox SelectedItem="{Binding Path=Location, Mode=TwoWay}" AutoCompletionSource="{Binding Path=DataContext.OwnerWorksheetViewModel.Worksheet.AllLocations, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" AllowSelectionNotInList="False" DefaultValueSelectionMode="Null" PopupMaxHeight="150" BorderBrush="Transparent" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Customer" Width="auto" MinWidth="70">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=Customer}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <wfCtlText:AutoCompleteTextBox SelectedItem="{Binding Path=Customer, Mode=TwoWay}" AutoCompletionSource="{Binding Path=DataContext.OwnerWorksheetViewModel.Worksheet.CustomersNames, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" AllowSelectionNotInList="False" DefaultValueSelectionMode="Null" PopupMaxHeight="150" BorderBrush="Transparent" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Project" Width="auto" MinWidth="70">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=Project}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <wfCtlText:AutoCompleteTextBox SelectedItem="{Binding Path=Project, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoCompletionSource="{Binding Path=DataContext.OwnerWorksheetViewModel.Worksheet.ProjectsNames, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" AllowSelectionNotInList="False" DefaultValueSelectionMode="Null" PopupMaxHeight="150" BorderBrush="Transparent" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Mode" Width="auto" MinWidth="50">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=TaskMode}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <ComboBox Text="{Binding Path=TaskMode, Mode=TwoWay}"
                                                      Style="{StaticResource ResourceKey=WhiteBgComboBoxType}">
                                                <ComboBoxItem Content="OnSite" />
                                                <ComboBoxItem Content="Remote" />
                                            </ComboBox>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Task Type" Width="auto" MinWidth="50">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=TaskType}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <ComboBox Text="{Binding Path=TaskType, Mode=TwoWay}"
                                                      Style="{StaticResource ResourceKey=WhiteBgComboBoxType}">
                                                <ComboBoxItem Content="Task" />
                                                <ComboBoxItem Content="Bug" />
                                                <ComboBoxItem Content="Meeting" />
                                            </ComboBox>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Task" Width="*">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=TaskTitle}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <wfCtlText:AutoCompleteTextBox x:Name="tb" VerticalAlignment="Center" BorderBrush="Transparent" SelectedItem="{Binding Path=TaskTitle, Mode=TwoWay}" AutoCompletionSource="{Binding Path=DataContext.OwnerWorksheetViewModel.Worksheet.AllTaskTitles, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" AllowSelectionNotInList="True" PopupMaxHeight="150" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Start" Width="auto" MinWidth="65">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=StartTime, Converter={StaticResource ResourceKey=TimeSpanConverter}}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <controls:TimePicker SelectedTime="{Binding StartTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="White" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="End" Width="auto" MinWidth="65">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock Text="{Binding Path=EndTime, Converter={StaticResource ResourceKey=TimeSpanConverter}}" />
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                    <DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <controls:TimePicker SelectedTime="{Binding EndTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="White" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellEditingTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="Total" Width="auto" MinWidth="90" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Border BorderThickness="1" BorderBrush="Transparent">
                                                <TextBlock>
                                            <TextBlock.Text>
                                                <MultiBinding StringFormat="{}{0} ({1})">
                                                    <Binding Path="TotalTime" Converter="{StaticResource ResourceKey=TimeSpanConverter}" />
                                                    <Binding Path="TotalTimeDecimal" />
                                                </MultiBinding>
                                            </TextBlock.Text>
                                                </TextBlock>
                                            </Border>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                            </DataGrid.Columns>
                        </DataGrid>

                        <GridSplitter Grid.Column="1"
                                  Background="Transparent"
                                  Width="5"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch"
                                  ResizeBehavior="PreviousAndNext"
                                  ResizeDirection="Columns" />

                        <Border Grid.Column="2"
                                DataContext="{Binding Path=SelectedItem, ElementName=TasksGrid}"
                                Padding="5"
                                BorderThickness="1"
                                BorderBrush="{StaticResource ResourceKey=DataGridLinesColor}"
                                TextElement.Foreground="{StaticResource ResourceKey=ContentsBgBrush}"
                                TextElement.FontSize="12">
                            <DockPanel LastChildFill="True">
                                <TextBlock DockPanel.Dock="Top"
                                           Text="Task Details" 
                                           FontSize="30" 
                                           FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />

                                <TabControl Margin="0,5,0,0">
                                    <TabItem Header="Description">
                                        <DockPanel LastChildFill="True">
                                            <TextBox Text="{Binding Path=TaskDescription}" 
                                                     AcceptsReturn="True" 
                                                     TextWrapping="Wrap" 
                                                     VerticalScrollBarVisibility="Auto" />
                                        </DockPanel>
                                    </TabItem>
                                    
                                    <TabItem Header="Notes">
                                        <TextBox Text="{Binding Path=Notes}" 
                                                 AcceptsReturn="True" 
                                                 TextWrapping="Wrap" 
                                                 VerticalScrollBarVisibility="Auto" />
                                    </TabItem>
                                </TabControl>
                                
                                <!--<ScrollViewer Margin="0,5,0,0" 
                                              VerticalScrollBarVisibility="Auto" 
                                              HorizontalScrollBarVisibility="Disabled">
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Text="Description" />
                                        <TextBox Text="{Binding Path=TaskDescription}" 
                                             Height="55" 
                                             AcceptsReturn="True" 
                                             TextWrapping="Wrap" 
                                             VerticalScrollBarVisibility="Auto" />
                                        <TextBlock Text="Notes" />
                                        <TextBox Text="{Binding Path=Notes}" 
                                             Height="55" 
                                             AcceptsReturn="True" 
                                             TextWrapping="Wrap" 
                                             VerticalScrollBarVisibility="Auto" />
                                    </StackPanel>
                                </ScrollViewer>-->
                            </DockPanel>
                        </Border>
                    </Grid>
                    
                    <GridSplitter Grid.Row="1"
                                  Background="Transparent"
                                  Height="5"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch"
                                  ResizeBehavior="PreviousAndNext"
                                  ResizeDirection="Rows" />

                    <Border Grid.Row="2"
                            Padding="5"
                            TextElement.Foreground="{StaticResource ResourceKey=ContentsBgBrush}" 
                            TextElement.FontSize="14"
                            BorderThickness="1"
                            BorderBrush="{StaticResource ResourceKey=DataGridLinesColor}">
                        <DockPanel LastChildFill="True">
                            <TextBlock Text="Summary"
                                       DockPanel.Dock="Top"
                                       FontSize="30"
                                       FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />
                            
                            <Grid DockPanel.Dock="Bottom">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto" />
                                    <ColumnDefinition Width="auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition Height="auto" />
                                </Grid.RowDefinitions>

                                <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0">
                                    <Border VerticalAlignment="Center">
                                        <wfCtlCommon:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Application/time.png" />
                                    </Border>
                                    <Border VerticalAlignment="Center" Margin="2,0,0,0">
                                        <TextBlock Text="Total worked time: " VerticalAlignment="Center" />
                                    </Border>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0">
                                    <Border VerticalAlignment="Center">
                                        <wfCtlCommon:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Application/time_go.png" />
                                    </Border>
                                    <Border VerticalAlignment="Center" Margin="2,0,0,0">
                                        <TextBlock Text="Overtime worked: " VerticalAlignment="Center" />
                                    </Border>
                                </StackPanel>

                                <TextBlock Grid.Row="0" Grid.Column="1">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}{0} ({1})">
                                        <Binding Path="OwnerWorksheetViewModel.SelectedTrackingDay.Summary.AllTasksTotalTime" Converter="{StaticResource ResourceKey=TimeSpanConverter}" />
                                        <Binding Path="OwnerWorksheetViewModel.SelectedTrackingDay.Summary.AllTasksTotalTimeDecimal" />
                                    </MultiBinding>
                                </TextBlock.Text>
                                </TextBlock>
                                <TextBlock Grid.Row="1" Grid.Column="1">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}{0} ({1})">
                                        <Binding Path="OwnerWorksheetViewModel.SelectedTrackingDay.Summary.Overtime" Converter="{StaticResource ResourceKey=TimeSpanConverter}" />
                                        <Binding Path="OwnerWorksheetViewModel.SelectedTrackingDay.Summary.OvertimeDecimal" />
                                    </MultiBinding>
                                </TextBlock.Text>
                                </TextBlock>
                            </Grid>
                            
                            <DataGrid Margin="5"
                                      CanUserAddRows="False"
                                      CanUserDeleteRows="False"
                                      ItemsSource="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay.Summary.TasksSummary}">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="Task" Binding="{Binding Path=Title}" Width="*" IsReadOnly="True" />
                                    <DataGridTextColumn Header="Total" Width="auto" IsReadOnly="True">
                                        <DataGridTextColumn.Binding>
                                            <MultiBinding StringFormat="{}{0} ({1})">
                                                <Binding Path="TotalTime" Converter="{StaticResource ResourceKey=TimeSpanConverter}" />
                                                <Binding Path="TotalTimeDecimal" />
                                            </MultiBinding>
                                        </DataGridTextColumn.Binding>
                                    </DataGridTextColumn>
                                </DataGrid.Columns>
                            </DataGrid>
                        </DockPanel>
                    </Border>
                </Grid>
                
                <DockPanel.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="True">
                                <Setter Property="Control.Visibility" Value="Collapsed" />
                                <Setter Property="Control.Opacity" Value="0" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="False">
                                <Setter Property="Control.Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DockPanel.Style>
            </DockPanel>
            
            <Border Margin="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="This day does not contain tracking data yet."
                               Foreground="Black" />
                    
                    <Button Margin="0,20,0,0" 
                            Cursor="Hand"
                            Background="Transparent"
                            Command="{Binding StartTrackingForCurrentDayCommand}"
                            Style="{StaticResource ResourceKey=HoverButtonStyle}">
                        <Button.Content>
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                <Border VerticalAlignment="Center">
                                    <wfCtlCommon:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Application/to_do_list.png" />
                                </Border>
                                <TextBlock Text="Start tracking for this day" 
                                           Margin="5,0,0,0"
                                           VerticalAlignment="Center" />
                            </StackPanel>
                        </Button.Content>
                    </Button>
                </StackPanel>
                
                <Border.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="True">
                                <Setter Property="Control.Visibility" Value="Visible" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="False">
                                <Setter Property="Control.Visibility" Value="Collapsed" />
                                <Setter Property="Control.Opacity" Value="0" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
            </Border>
        </Grid>
        
    </Grid>

</UserControl>